<form id="tagForm">
    <input name="id" type="hidden" th:value="${tag?.id}">
    <div class="form-group row">
        <label for="name" class="col-sm-2 col-form-label">标签分类</label>
        <div class="col-sm-10">
            <select id="category-select" class="form-control" name="categoryId" required>
                <block th:each="category: ${categories}">
                    <option th:if="${#lists.isEmpty(category.children)}" th:value="${category.id}" th:label="${category.name}" th:selected="${tag?.categoryId == category.id}"></option>
                    <optgroup th:unless="${#lists.isEmpty(category.children)}" th:label="${category.name}">
                        <option th:each="child: ${category.children}" th:value="${child.id}" th:label="${child.name}" th:selected="${tag?.categoryId == child.id}"></option>
                    </optgroup>
                </block>
            </select>
            <div class="invalid-feedback">请选择标签分类</div>
        </div>
    </div>
    <div class="form-group row">
        <label for="name" class="col-sm-2 col-form-label">标签名称</label>
        <div class="col-sm-10">
            <input type="text" th:value="${tag?.name}" name="name" class="form-control" id="name"
                   placeholder="填写分类名称" required>
            <div class="invalid-feedback">请填写标签名称</div>
        </div>
    </div>
    <div class="form-group row">
        <label for="description" class="col-sm-2 col-form-label">标签描述</label>
        <div class="col-sm-10">
            <input type="text" th:value="${tag?.description}" name="description" class="form-control"
                   id="description"
                   placeholder="填写分类描述" required>
            <div class="invalid-feedback">请填写标签描述</div>
        </div>
    </div>
    <div class="form-group row">
        <label for="description" class="col-sm-2 col-form-label">排序号</label>
        <div class="col-sm-10">
            <input type="number" th:value="${tag?.sortNumber}" name="sortNumber" class="form-control"
                   id="sortNumber" required>
            <div class="invalid-feedback">请填写排序号</div>
        </div>
    </div>
</form>